package com.rpj.stauy.controller;

import com.rpj.stauy.service.RagService;
import dev.langchain4j.data.document.Document;
import dev.langchain4j.data.document.loader.FileSystemDocumentLoader;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping
public class RagController {

    @Resource
    private RagService ragService;
    @Resource
    private InMemoryEmbeddingStore<TextSegment> embeddingStore;


    // http://localhost:9101/rag/add
    @GetMapping(value = "/rag/add")
    public String testAdd(){
        //文件对象，
        Document document = FileSystemDocumentLoader.loadDocument("E:\\aaa\\错误编码.docx");
        //存入内存库（向量数据库）
        EmbeddingStoreIngestor.ingest(document,embeddingStore);
        String chatted = ragService.chat("错误码00000和A0001分别是什么");
        System.out.println(chatted);

        return chatted;


    }

}
